home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Magazin/MacEasy 25
/
Mac Magazin and MacEasy Magazine CD - Issue 25.iso
/
Grafik & Text
/
Alpha
/
Tcl
/
Modes
/
html.tcl
< prev
next >
Wrap
Text File
|
1996-08-15
|
10KB
|
311 lines
#================================================================================
#
# html.tcl, HTML mode 1.2: macros and bindings for editing HTML documents.
#
#================================================================================
#
# version 0.24 (16 July 95) by Scott W. Brim <swb1@cornell.edu>
# version 1.0 -- 1.2 (August 96) by Johan Linde <jl@theophys.kth.se>
#
# See HTML Help in the Help folder.
#
# Original ideas taken from Marc Andreesen's html.el and Tom Scavo's latex.tcl.
#
# If you make improvements to this file, please share them!
#
# Johan Linde <jl@theophys.kth.se>
#
#================================================================================
# called by Alpha to load HTML in.
proc htmlDummy {} {}
proc htmlMenu {} {}
#===============================================================================
# Global variables and their management
#===============================================================================
if {![info exists htmlMenu]} {set htmlMenu "•135"}
set commentPreString "<!-- "
set commentSufString " -->"
# Unsetting old flags and variables which may be defined in arrdefs.tcl
catch {unset HTMLmodeVars(dlEntries)}
catch {unset HTMLmodeVars(useCtlCmd)}
catch {unset HTMLmodeVars(allContainers)}
catch {unset HTMLmodeVars(quotedAttrs)}
catch {unset HTMLmodeVars(htmlBindPrefix)}
catch {unset HTMLmodeVars(htmlSBindPrefix)}
catch {unset HTMLmodeVars(htmlMenuPrefix)}
catch {unset HTMLmodeVars(htmlSMenuPrefix)}
catch {unset HTMLmodeVars(URLAttrs)}
catch {unset HTMLmodeVars(ColorAttrs)}
catch {unset HTMLmodeVars(elemAttrsForAll)}
catch {unset HTMLmodeVars(useStatusBar)}
# Browser
if {![info exists browserSig]} {set browserSig MOSS}
# newModeVar HTML browserSig {MOSS} 0
# word breaking and word wrapping
newModeVar HTML wordBreak {\w+} 0
newModeVar HTML wordBreakPreface {(\W)} 0
newModeVar HTML wrapBreak {[\w_]+} 0
newModeVar HTML wrapBreakPreface {([^\w_])} 0
newModeVar HTML wordWrap 1 1
newModeVar HTML prefixString $commentPreString 0
newModeVar HTML suffixString $commentSufString 0
# URL to home page.
newModeVar HTML baseURL {} 0
newModeVar HTML basePath {} 0
# Paths to footer files.
newModeVar HTML footers {} 0
# Tag color
newModeVar HTML tagColor blue 0
# Should elements be lower case?
newModeVar HTML useLowerCase 0 1
# Should •'s be inserted?
newModeVar HTML useTabMarks 1 1
# Is <p> a container?
newModeVar HTML pIsContainer 1 1
# Are LI DT and DD containers
newModeVar HTML lidtAreContainers 0 1
# A list of URLs, cached, to pick from for insertion
newModeVar HTML URLs {} 0
# A window cache with frames.
newModeVar HTML windows {} 0
# When browser is launched, should it be brought to front?
newModeVar HTML browseInForeground 1 1
# list of commonly used character entities
newModeVar HTML defaultCommonChars {"less than" "greater than" "ampersand"} 0
newModeVar HTML commonChars $HTMLmodeVars(defaultCommonChars) 0
# Which HTML package?
newModeVar HTML htmlPackageToUse 1 0
# Include event handlers in attribute dialog?
newModeVar HTML inclEventHandler 0 1
# Beep when asking for attributes in the status bar?
newModeVar HTML promptNoisily 1 1
# Input from big windows?
newModeVar HTML useBigWindows 1 1
# JavaScript stuff
newModeVar HTML JavaScriptColoring 0 1
newModeVar HTML JavaScriptColor magenta 0
newModeVar HTML stringColor green 0
newModeVar HTML elecRBrace 0 1
newModeVar HTML elecLBrace 0 1
# These mode variables should not appear in the config dialog.
set HTMLinvisibleModeVars(htmlPackageToUse) 1
set HTMLinvisibleModeVars(footers) 1
set HTMLinvisibleModeVars(windows) 1
set HTMLinvisibleModeVars(URLs) 1
set HTMLinvisibleModeVars(defaultCommonChars) 1
set HTMLinvisibleModeVars(commonChars) 1
set HTMLinvisibleModeVars(browserSig) 1
set HTMLinvisibleModeVars(baseURL) 1
set HTMLinvisibleModeVars(basePath) 1
# These attributes are URLs.
set htmlURLAttr {HREF= SRC= LOWSRC= ACTION= USEMAP= BACKGROUND= CODEBASE= PLUGINSPAGE=}
# These element attributes are colors
set htmlColorAttr {BGCOLOR= TEXT= LINK= VLINK= ALINK= COLOR= BORDERCOLOR=}
# These attributes are windows
set htmlWindowAttr {TARGET=}
# Special cases with URLs, colors and windows
set htmlSpecURL {}
set htmlSpecColor {}
set htmlSpecWindow {}
# These elements can be in document HEAD.
set htmlHeadElements1 {BASE ISINDEX LINK META SCRIPT}
set htmlHeadElements3 {BASE ISINDEX LINK META}
# These elements are plug-ins.
set htmlPlugins {EMBED LIVEAUDIO LIVEVIDEO "QUICKTIME MOVIE" "QUICKTIME VR" REALAUDIO}
# HTML mode version
set htmlVersion 1.2
#
# Internal Globals
#
set htmlCurSel ""
set htmlIsSel 0
set htmlExtIsLoaded 0
set html32IsLoaded 0
set htmlIsLoaded 1
if { [catch {source "$HOME:Tcl:Modes:htmlEngine.tcl"}] } {
set htmlIsLoaded 0
beep
alertnote "Loading of htmlEngine.tcl failed"
}
if { [catch {source "$HOME:Tcl:Modes:htmlElems.tcl"}] } {
set htmlIsLoaded 0
beep
alertnote "Loading of htmlElems.tcl failed"
}
if { [catch {source "$HOME:Tcl:Modes:htmlMenu.tcl"}] } {
set htmlIsLoaded 0
beep
alertnote "Loading of htmlMenu.tcl failed"
}
if {!$HTMLmodeVars(useBigWindows) && [catch {source "$HOME:Tcl:Modes:htmlExtra.tcl"}] } {
set htmlIsLoaded 0
beep
alertnote "Loading of htmExtra.tcl failed"
}
#
# Read custom elements
#
# A more advance version of this proc will be needed in future versions of
# HTML mode, which checks that the custom additions don't conflict with
# new elements added to HTML mode.
proc htmlReadAdditions {} {
global PREFS htmlElemAttrRequired1 htmlElemAttrOptional1 htmlElemAttrChoices1
global htmlElemAttrNumber1 htmlElemEventHandler1 htmlElemKeyBinding htmlElemProc
global htmlExtIsLoaded htmlURLAttr htmlColorAttr htmlWindowAttr htmlPlugins
global htmlSpecURL htmlSpecColor htmlSpecWindow
message "Loading custom elements…"
htmlExtensions
set htmlExtIsLoaded 1
rename htmlExtensions ""
if {![catch {set fid [open $PREFS:HTMLadditions.tcl r]}]} {
set additions [string trimright [read $fid] "\n"]
close $fid
foreach line [lrange [split $additions "\n"] 1 end] {
catch {eval [lindex $line 1]}
}
}
}
#
# Color support
#
proc htmlColorizing {} {
global HTMLmodeVars HTMLwords htmlElemAttrOptional1 htmlElemAttrRequired1
global htmlExtIsLoaded htmlElemEventHandler1
set HTMLKeyWords {}
if {[info exists HTMLwords]} {set HTMLKeyWords [concat $HTMLKeyWords $HTMLwords]}
if {$HTMLmodeVars(JavaScriptColoring)} {
if {!$htmlExtIsLoaded} {
htmlExtensions
set htmlExtIsLoaded 1
rename htmlExtensions ""
}
set allHTMLwords [array names htmlElemAttrOptional1]
foreach elem $allHTMLwords {
lappend allHTMLkeywords "<${elem}" "/${elem}"
if {[info exists htmlElemAttrRequired1($elem)]} {
foreach attr $htmlElemAttrRequired1($elem) {
if {[lsearch -exact $allHTMLkeywords $attr] < 0} {
lappend allHTMLkeywords $attr
}
}
}
foreach attr $htmlElemAttrOptional1($elem) {
if {[lsearch -exact $allHTMLkeywords $attr] < 0} {
lappend allHTMLkeywords $attr
}
}
}
lappend allHTMLkeywords "<INPUT"
set JavaScriptWords {break continue for in function if else new return this var while with true false }
foreach elem [array names htmlElemEventHandler1] {
foreach event $htmlElemEventHandler1($elem) {
if {[lsearch -exact $JavaScriptWords $event] < 0} {
lappend JavaScriptWords $event
}
}
}
regModeKeywords -i "<" -i ">" -I $HTMLmodeVars(tagColor) -e "//" -b "/*" "*/" \
-s $HTMLmodeVars(stringColor) -k $HTMLmodeVars(JavaScriptColor) \
HTML $JavaScriptWords
regModeKeywords -a -k $HTMLmodeVars(tagColor) \
HTML [concat $HTMLKeyWords $allHTMLkeywords]
} else {
regModeKeywords -b "<" ">" -c $HTMLmodeVars(tagColor) \
-k $HTMLmodeVars(tagColor) HTML $HTMLKeyWords
}
}
# Change color when a color variable is changed.
proc htmlChangeColorizing {name1 name2 op} {
global HTMLmodeVars
if {$name2 == "JavaScriptColoring" } {
htmlColorizing
message "Coloring may not change until you switch to another window."
} elseif {$name2 == "tagColor"} {
if {!$HTMLmodeVars(JavaScriptColoring)} {
regModeKeywords -a -c $HTMLmodeVars(tagColor) HTML
} else {
htmlColorizing
message "Coloring may not change until you switch to another window."
}
} elseif {$name2 == "JavaScriptColor" && $HTMLmodeVars(JavaScriptColoring)} {
htmlColorizing
message "Coloring may not change until you switch to another window."
}
centerRedraw
}
proc htmlShadowAttrUse {name1 name2 op} {
global HTMLmodeVars htmlMenu
if {$HTMLmodeVars(useBigWindows)} {
enableMenuItem $htmlMenu "Use Attributes" off
} else {
enableMenuItem $htmlMenu "Use Attributes" on
}
}
trace variable HTMLmodeVars(tagColor) w htmlChangeColorizing
trace variable HTMLmodeVars(JavaScriptColor) w htmlChangeColorizing
trace variable HTMLmodeVars(JavaScriptColoring) w htmlChangeColorizing
trace variable HTMLmodeVars(useBigWindows) w htmlShadowAttrUse
if {$htmlIsLoaded} {
if {[file exists $PREFS:HTMLadditions.tcl]} {catch {htmlReadAdditions} }
rename htmlReadAdditions ""
htmlBindKeys
message "Building HTML menu…"
htmlBuildMenu
htmlColorizing
message "HTML initialization complete."
} else {
message "HTML initialization failed."
}
unset htmlIsLoaded
#===============================================================================
proc parseFuncsHTML {} {
set pos 0
while {[set res [search -s -f 1 -r 1 -i 1 -n {name=\"?\w+\"?} $pos]] != ""} {
set text [getText [car $res] [expr [nextLineStart [cadr $res]] - 1]]
if {[regexp -nocase {name=\"?(\w+)\"?} $text dummy word]} {
lappend m $word [lineStart [car $res]]
}
set pos [cadr $res]
}
return $m
}